package com.wangyb.wework.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.wangyb.wework.bo.WwGroupchatAutoPullQueryBo;
import com.wangyb.wework.service.contact.IWwGroupchatAutoPullService;
import com.wangyb.wework.vo.WwGroupchatAutoPullVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 自动拉群Controller
 *
 * @author wangyb
 * @date 2021-07-13
 */
@Api(value = "自动拉群控制器", tags = {"自动拉群管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wework/groupchatAutoPull")
public class WwGroupchatAutoPullController extends BaseController {

	private final IWwGroupchatAutoPullService iWwGroupchatAutoPullService;

	/**
	 * 查询自动拉群列表
	 */
	@ApiOperation("查询自动拉群列表")
	@PreAuthorize("@ss.hasPermi('wework:groupchatAutoPull:list')")
	@GetMapping("/list")
	public TableDataInfo<WwGroupchatAutoPullVo> list(@Validated WwGroupchatAutoPullQueryBo bo) {
		return iWwGroupchatAutoPullService.queryPageList(bo);
	}

	/**
	 * 导出自动拉群列表
	 */
	@ApiOperation("导出自动拉群列表")
	@PreAuthorize("@ss.hasPermi('wework:groupchatAutoPull:export')")
	@Log(title = "自动拉群", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<WwGroupchatAutoPullVo> export(@Validated WwGroupchatAutoPullQueryBo bo) {
		List<WwGroupchatAutoPullVo> list = iWwGroupchatAutoPullService.queryList(bo);
		ExcelUtil<WwGroupchatAutoPullVo> util = new ExcelUtil<WwGroupchatAutoPullVo>(WwGroupchatAutoPullVo.class);
		return util.exportExcel(list, "自动拉群");
	}

	/**
	 * 获取自动拉群详细信息
	 */
	@ApiOperation("获取自动拉群详细信息")
	@PreAuthorize("@ss.hasPermi('wework:groupchatAutoPull:query')")
	@GetMapping("/{id}")
	public AjaxResult<WwGroupchatAutoPullVo> getInfo(@NotNull(message = "主键不能为空")
													 @PathVariable("id") Long id) {
		return AjaxResult.success(iWwGroupchatAutoPullService.queryById(id));
	}

	/**
	 * 新增自动拉群
	 */
	@ApiOperation("新增自动拉群")
	@PreAuthorize("@ss.hasPermi('wework:groupchatAutoPull:add')")
	@Log(title = "自动拉群", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody WwGroupchatAutoPullVo vo) {
		return toAjax(iWwGroupchatAutoPullService.insertByAddBo(vo) ? 1 : 0);
	}

	/**
	 * 修改自动拉群
	 */
	@ApiOperation("修改自动拉群")
	@PreAuthorize("@ss.hasPermi('wework:groupchatAutoPull:edit')")
	@Log(title = "自动拉群", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody WwGroupchatAutoPullVo bo) {
		return toAjax(iWwGroupchatAutoPullService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除自动拉群
	 */
	@ApiOperation("删除自动拉群")
	@PreAuthorize("@ss.hasPermi('wework:groupchatAutoPull:remove')")
	@Log(title = "自动拉群" , businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iWwGroupchatAutoPullService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
